#pragma once

#define SPDM_MAX_VERSION 3

/* SPDM ERROR CODE AND DATA */
#define SPDM_ERROR_CODE_INVALID_REQUEST		0x01
#define   SPDM_ERROR_DATA_INVALID_REQUEST	0x00
#define SPDM_ERROR_CODE_BUSY			0x03
#define   SPDM_ERROR_DATA_BUSY			0x00
#define SPDM_ERROR_CODE_UNEXPECTED_REQUEST	0x04
#define SPDM_ERROR_CODE_UNSPECIFIED		0x05
#define SPDM_ERROR_CODE_UNSUPPORTED_REQUEST	0x07
#define SPDM_ERROR_CODE_MAJOR_VERSION_MISMATCH	0x41
#define SPDM_ERROR_CODE_RESPONSE_NOT_READY	0x42
#define SPDM_ERROR_CODE_REQUEST_RESYNCH		0x43

/* GET_VERSION/VERSION */
#define SPDM_VERSION_NUMBER_ENTRY_MAX 1
#define SPDM_VERSION_NUMBER_ENTRY_SHIFT_BIT 8

/* SPDM CAPABILITIES */
#define SPDM_CACHE_CAP			(BIT(0) << 0)
#define SPDM_CERT_CAP 			(BIT(1) << 0)
#define SPDM_CHAL_CAP 			(BIT(2) << 0)
#define SPDM_MEAS_CAP_NO_SIG		(BIT(3) << 0)
#define SPDM_MEAS_CAP_SIG		(BIT(4) << 0)
#define SPDM_ENCRYPT_CAP 		(BIT(6) << 0)
#define SPDM_MAC_CAP 			(BIT(7) << 0)
#define SPDM_MUT_AUTH_CAP 		(BIT(0) << 8)
#define SPDM_KEY_EX_CAP 		(BIT(1) << 8)
#define SPDM_PSK_CAP 			(BIT(2) << 8)
#define SPDM_ENCAP_CAP 			(BIT(4) << 8)
#define SPDM_HBEAT_CAP 			(BIT(5) << 8)
#define SPDM_KEY_UPD_CAP 		(BIT(6) << 8)
#define SPDM_HANDSHAKE_IN_THE_CLEAR_CAP	(BIT(7) << 8)
#define SPDM_PUB_KEY_ID_CAP 		(BIT(0) << 16)
#define SPDM_CHUNK_CAP 			(BIT(1) << 16)

/* SPDM ALGORHTMS */
#define SPDM_EXT_ASYM_SEL_COUNT 1
#define SPDM_EXT_HASH_SEL_COUNT 1

#define SPDM_ALGORITHMS_BASE_ALGO_TPM_ALG_RSASSA_2048		(BIT(0) << 0)
#define SPDM_ALGORITHMS_BASE_ALGO_TPM_ALG_RSAPSS_2048		(BIT(1) << 0)
#define SPDM_ALGORITHMS_BASE_ALGO_TPM_ALG_RSASSA_3072		(BIT(2) << 0)
#define SPDM_ALGORITHMS_BASE_ALGO_TPM_ALG_RSAPSS_3072		(BIT(3) << 0)
#define SPDM_ALGORITHMS_BASE_ALGO_TPM_ALG_ECDSA_ECC_NIST_P256	(BIT(4) << 0)
#define SPDM_ALGORITHMS_BASE_ALGO_TPM_ALG_RSASSA_4096		(BIT(5) << 0)
#define SPDM_ALGORITHMS_BASE_ALGO_TPM_ALG_RSAPSS_4096		(BIT(6) << 0)
#define SPDM_ALGORITHMS_BASE_ALGO_TPM_ALG_ECDSA_ECC_NIST_P384	(BIT(7) << 0)
#define SPDM_ALGORITHMS_BASE_ALGO_TPM_ALG_ECDSA_ECC_NIST_P521	(BIT(0) << 8)

#define SPDM_ALGORITHMS_BASE_HASH_TPM_ALG_SHA_256	BIT(0)
#define SPDM_ALGORITHMS_BASE_HASH_TPM_ALG_SHA_384	BIT(1)
#define SPDM_ALGORITHMS_BASE_HASH_TPM_ALG_SHA_512	BIT(2)
#define SPDM_ALGORITHMS_BASE_HASH_TPM_ALG_SHA3_256	BIT(3)
#define SPDM_ALGORITHMS_BASE_HASH_TPM_ALG_SHA3_384	BIT(4)
#define SPDM_ALGORITHMS_BASE_HASH_TPM_ALG_SHA3_512	BIT(5)

#define SPDM_ALGORITHMS_MEAS_HASH_RAW_BIT_STREAM	BIT(0)
#define SPDM_ALGORITHMS_MEAS_HASH_TPM_ALG_SHA_256	BIT(1)
#define SPDM_ALGORITHMS_MEAS_HASH_TPM_ALG_SHA_384	BIT(2)
#define SPDM_ALGORITHMS_MEAS_HASH_TPM_ALG_SHA_512	BIT(3)
#define SPDM_ALGORITHMS_MEAS_HASH_TPM_ALG_SHA3_256	BIT(4)
#define SPDM_ALGORITHMS_MEAS_HASH_TPM_ALG_SHA3_384	BIT(5)
#define SPDM_ALGORITHMS_MEAS_HASH_TPM_ALG_SHA3_512	BIT(6)

/* SPDM CHALLENGE */
#define SPDM_NONCE_SIZE 32

/* SPDM GET_MEASUREMENTS/MEASUREMENTS */
#define SPDM_MEASUREMENT_REQ_ATTR_GEN_SIGNATURE		BIT(0)
#define SPDM_MEASUREMENT_REQ_ATTR_RAW_BIT_STREAM	BIT(1)


#define SPDM_MEASUREMENT_BLOCK_DMTF_SPEC 0x01

#define SPDM_MEASUREMENT_BLOCK_DMTF_TYPE_IMMUTABLE_ROM 0x00
#define SPDM_MEASUREMENT_BLOCK_DMTF_TYPE_MUTABLE_FIRMWARE 0x01
#define SPDM_MEASUREMENT_BLOCK_DMTF_TYPE_HARDWARE_CONFIG 0x02
#define SPDM_MEASUREMENT_BLOCK_DMTF_TYPE_FIRMWARE_CONFIG 0x03

#define SPDM_MEASUREMENT_OPERATION_TOTAL_NUMBER 0x00
#define SPDM_MEASUREMENT_OPERATION_ALL_MEASUREMENTS 0xFF

/* SPDM Version String */
#define SPDM_PREFIX_VERSION_12 "dmtf-spdm-v1.2.*dmtf-spdm-v1.2.*dmtf-spdm-v1.2.*dmtf-spdm-v1.2.*"

/* Signature Generation Context */
#define SPDM_SIGN_CONTEXT_M1M2_RSP "responder-challenge_auth signing"
#define SPDM_SIGN_CONTEXT_M1M2_REQ "requester-challenge_auth signing"
#define SPDM_SIGN_CONTEXT_L1L2_RSP "responder-measurements signing"
#define SPDM_SIGN_CONTEXT_L1L2_REQ "responder-measurements signing"
